package com.lj.sys.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.lj.common_web.annotation.ResponseResultVo;
import com.lj.sys.param.SysDeptSaveParam;
import com.lj.sys.param.SysDeptUpdateParam;
import com.lj.sys.result.SysDeptInfoResult;
import com.lj.sys.service.SysDeptService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统部门表 前端控制器
 * </p>
 *
 * @author luojing
 * @since 2024-12-20 21:27:32
 */
@RestController
@RequestMapping("/sys/sys_dept")
@ResponseResultVo
@Tag(name = "系统部门表 管理")
public class SysDeptController {

    @Resource
    private SysDeptService sysDeptService;

    @GetMapping("/tree")
    @SaCheckPermission("sys:sys_dept:tree")
    @Operation(summary = "部门树", description = "主要用于总览部门管理")
    public List<SysDeptInfoResult> tree() {
        return sysDeptService.tree();
    }

    @GetMapping("/info/{id}")
    @SaCheckPermission("sys:sys_dept:info")
    @Operation(summary = "系统部门表 信息")
    public SysDeptInfoResult info(@PathVariable("id") @Parameter(name = "id", description = "系统部门表 id") Long id) {
        if (id == null) {
            return null;
        }
        return sysDeptService.info(id);
    }

    @PostMapping("/save")
    @SaCheckPermission("sys:sys_dept:save")
    @Operation(summary = "系统部门表 新增")
    public void save(@RequestBody @Validated SysDeptSaveParam param) {
        sysDeptService.save(param);
    }

    @PostMapping("/update")
    @SaCheckPermission("sys:sys_dept:update")
    @Operation(summary = "系统部门表 更新")
    public void update(@RequestBody @Validated SysDeptUpdateParam param) {
        sysDeptService.update(param);
    }

    @PostMapping("/delete/{id}")
    @SaCheckPermission("sys:sys_dept:delete")
    @Operation(summary = "系统部门表 删除")
    public void delete(@PathVariable("id") @Parameter(name = "id", description = "系统部门表 id") Long id) {
        sysDeptService.delete(id);
    }


}

